// pages/details/detail.js
const app = getApp();
const apiUrl = app.data.url;
const network = require('../../utils/network.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    lat: "",
    long: "",
    addressName:"",
    showView: false,
    // 弹窗显示控制
    isShow: false,
    wxNum:'4234234',
    id:''
  },
  //隐藏弹框
  hideDialog() {
    this.setData({
      isShow: !this.data.isShow
    })
  },

  //展示弹框
  showDialog() {
    console.log(1)
    this.setData({
      isShow: !this.data.isShow
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  showmap:function(){
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  },
  onLoad: function (options) {
    const that = this;
    wx.getStorage({
      key: 'address',
      success: function (res) {
        const lat = res.data.lat;
        const long = res.data.long;
        const name = res.data.name;
        that.setData({
          lat: lat,
          long: long,
          addressName :name
        })     
        var url = apiUrl + 'api/info/querydetail';
        var params={
          "id": options.id,             //  该条信息的id
            "uid": "",            //  当前用户id，可以不填写（
            "lat": lat,           //  纬度 默认是杭州的维度
            "lng": long,
        }
        network.POST(url, params).then(() => {
          //请求成功的操作       
          var _data = app.netWorkData.result;
          that.setData({
            list: _data.data,
            id: _data.data.id
          });
     
        });
        
      }

    });
    showView: (options.showView == "true" ? true : false)
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  //复制事件
  clipBorderData() {
    let that = this;
    wx.setClipboardData({
      data: that.data.wxNum,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            that.setData({
              isShow: !that.data.isShow
            })
            wx.showToast({
              title: '复制成功',
              icon: 'none',
              duration: 2000
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    var that = this;
    var id = that.data.id;
    console.log(that.data.id)
    return {
      title: '留守猫',
      path: 'pages/details/detail？id='+id
    }
  }
})